﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PostSharp;
using System.Transactions;
using PostSharp.Aspects;

namespace TestProjectCS.Attributes
{
	[AttributeUsage(AttributeTargets.Method)]
	[Serializable]
	public class RollingBackTransactionAttribute : OnMethodBoundaryAspect
	{
		public override void OnEntry(MethodExecutionArgs eventArgs)
		{
			TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, TimeSpan.FromMinutes(12));
            eventArgs.MethodExecutionTag = scope;
		}

		public override void OnExit(MethodExecutionArgs eventArgs)
		{
			TransactionScope scope = (TransactionScope)eventArgs.MethodExecutionTag;
			if (scope != null)
				scope.Dispose();
		}
	}
}
